import {
    Base
} from '../../utils/base.js'
class Cart extends Base {
    constructor() {
        super()
    }
    // 获取购物车
    getCart(params, callback) {
        var url = '/ddaigo-platform/cart/get';
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    // 清空购物车
    clearCart(params, callback) {
        var url = '/ddaigo-platform/cart/empty';
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    // 删除购物车商品
    deleteCart(params, callback) {
        var url = '/ddaigo-platform/cart/remove';
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    // 修改购物车
    upadateCart(params, callback) {
        var url = '/ddaigo-platform/cart/modify';
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    // 获取商品信息
    getGoodsById(params, callback) {
        var url = '/ddaigo-platform/goods/getGoodsById';
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    // 创建订单
    createOrderAndDetails(params, callback) {
        var url = '/ddaigo-platform/order/createOrderAndDetails';
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    //   优惠券列表
    getCouponList(params, callback) {
        var url = '/ddaigo-platform/coupon/receiveList';
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    //   领取优惠券
    getCoupon(params, callback) {
        var url = '/ddaigo-platform/coupon/receive';
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    formate(fmt, data) {
        var data = data ? data : 'yyyy-MM-dd hh:mm:ss'
        return (new Date(fmt)).cartFormat(data)
    }
    commonRequest(url, reType, params, callback) {
        var that = this;
        var param = {
            url: url,
            type: reType,
            data: params,
            sCallback: function (data) {
                typeof callback == 'function' && callback(data);
            },
            eCallback: data => {
                callback && callback({
                    status: false
                });
            }
        };
        this.request(param);
    }


}
module.exports = {
    Cart
}